package com.Maykk.Demo01;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * @ClassName: Demo04
 * @Description: TODO 通过私有构造方法实例化 Student 对象
 * @Author: MaykkStar@163.com
 */
public class Demo04 {
    public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        // 获取 Student 类的 Class 对象
        Class<Student> stuClass = Student.class;
        Constructor<Student> con = stuClass.getDeclaredConstructor(String.class, int.class, float.class, String.class);

        // 通过要抑制权限检测的对象来调用 setAccessible 方法，true 表示开启权限抑制
        con.setAccessible(true); // 抑制权限检测

        Student student = con.newInstance("Maykk", 18, 100.0f, "123456789");

        System.out.println(student);
    }
}